<template>
	<view class="user">
		<!-- 上方显示用户信息的区域 -->
		<view class="userinfo">
			<!-- 信息区域 -->
			<view class="top">
				<view class="avator">
					<uni-icons type="person-filled" size="30" :color="logColor"></uni-icons>
				</view>
				<!-- store.userInfo.username是从状态对象中获取已登录用户的信息中的姓名 -->
				<view class="uname" v-if="store.isLogin">
					<view>{{store.userInfo.username}}</view>
				</view>
				<view class="uname" v-else @tap="toLogin">点击登录</view>

			</view>
		</view>
		<!-- 下方显示的四项用户操作项 -->
		<view class="list">
			<uni-list>
				<uni-list-item v-for="item,index in manageList" :title="item.name" :show-extra-icon="true"
					:extra-icon="item.icon" clickable link @tap="navto(index)"></uni-list-item>
			</uni-list>
			<button type="default" class="btn" @tap="logout">退出登录</button>
		</view>
	</view>
</template>

<script setup>
	import {
		ref
	} from 'vue'
	import {
		userStore
	} from "../../store/userStore";


	let logColor = ref('#ccc')


	let store = userStore()


	const manageList = ref([{
		name: '美食景点收藏',
		icon: {
			color: '#56c48b',
			size: '22',
			type: 'shop'
		}
	}, {
		name: '电影收藏',
		icon: {
			color: '#ff6700',
			size: '22',
			type: 'location-filled'
		}
	}, {
		name: '修改密码',
		icon: {
			color: '#0225ff',
			size: '22',
			type: 'star'
		}
	}, {
		name: '退出登录',
		icon: {
			color: '#0081b9',
			size: '22',
			type: 'gear'
		}
	}])

	function navto(index) {
		uni.showToast({
			title: `你点击的是${manageList.value[index].name}`
		})
	}

	function toLogin() {
		uni.navigateTo({
			url: "/pages/login/login"
		})
	}

	function logout() {
		console.log('logout clicked'); // 添加日志输出
		store.clearUserInfo(); // 清除用户信息
		uni.showToast({
			title: "退出成功",
			icon: "success"
		});
	}
</script>

<style lang="scss">
	.userinfo {
		width: 100%;
		height: 360rpx;
		background-color: burlywood;

		.top {
			display: flex;
			align-items: center;
			left: 50px;
			position: absolute;
			top: 50px;

			.avator {
				width: 80rpx;
				height: 80rpx;
				border-radius: 50%;
				display: flex;
				left: 40rpx;
				line-height: 40rpx;
				margin-right: 40rpx;
				justify-content: center;
				align-items: center;
				background-color: #fff;
			}

			.uname {
				color: #fff;
			}
		}
	}

	.list {
		width: 710rpx;
		margin: 20rpx auto;
		border-radius: 10px;
	}
</style>